using System;
using System.Collections;
using System.IO;
using System.Xml;
using System.Xml.Serialization;

namespace Comix
{
    // Comic strip list
    [XmlRoot("comix")]
    public class ComicStripList
    {
        private ArrayList comicStripList;

        public ComicStripList()
        {
            comicStripList = new ArrayList();
        }

        [XmlElement("strip")]
        public Strip[] Strips
        {
            get
            {
                Strip[] strips = new Strip[comicStripList.Count];
                comicStripList.CopyTo(strips);
                return strips;
            }
            set
            {
                if (value == null) return;
                Strip[] strips = (Strip[])value;
                comicStripList.Clear();
                foreach (Strip strip in strips)
                    comicStripList.Add(strip);
            }
        }

        public int AddItem(Strip strip)
        {
            return comicStripList.Add(strip);
            //comicStripList.Sort(0,comicStripList.Count,IComparable )
        }

        public Strip getStripByIndex(int stripIndex)
        {
            if (stripIndex >= 0 && stripIndex < comicStripList.Count)
                return ((Strip)comicStripList[stripIndex]);
            return null;
        }

        public Strip getStripByName(string name) {
            for(int index=0;index<comicStripList.Count;index++)
            if (((Strip)comicStripList[index]).Name.Equals(name))
                return (Strip)comicStripList[index];
            return null;
        }

        public int Count { get { return comicStripList.Count; } }
    }

}